package com.example.carefree_server.service.impl.i_departmentImpl;

import com.example.carefree_server.entity.Activity;
import com.example.carefree_server.exception.AlreadyExistsException;
import com.example.carefree_server.mapper.m_departmentMapper.signInMapper;
import com.example.carefree_server.service.s_departmentService.signInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class signInServiceImpl implements signInService {

    @Autowired
    private signInMapper sIActivityMapper;

//    在尝试插入数据前，系统会先检查aid和sid的组合是否已存在于数据库中，如果存在，则抛出异常并阻止插入操作，从而避免了数据冗余。
    @Override
    public void dataAdd(Activity activity) {
        // 检查活动编号和学生编号组合是否存在
        Activity existingActivity = sIActivityMapper.checkActivityStudentExists(activity.getAid(), activity.getSid());
        if (existingActivity != null) {
            throw new AlreadyExistsException("本活动已有该生签到数据，请勿重复签到！");
        }
        // 插入数据
        sIActivityMapper.dataAdd(activity);
    }
}